package tinybase.pf;

import java.nio.ByteBuffer;

public class PageNum {
	@Override
	public String toString() {
		return "PageNum [pageNum=" + pageNum + "]";
	}

	private int pageNum;
	
	public static int PF_PAGE_UNSET = -3;
	public static int PAGENUM_SIZE= 4;
	
	public PageNum() {
		this.pageNum = PF_PAGE_UNSET;
	}
	
//	public PageNum(byte[] src) {
//		ByteBuffer bvf= ByteBuffer.wrap(src);
//		this.pageNum= bvf.getInt();
//	}
	
	public void getFromByte(byte[] src) {
		ByteBuffer buf= ByteBuffer.wrap(src);
		this.pageNum= buf.getInt();
	}
	
	public byte[] toBytes() {
		byte[] arr= new byte[PAGENUM_SIZE];
		ByteBuffer buf= ByteBuffer.wrap(arr);
		buf.putInt(this.pageNum);
		return arr;
	}
	
	public PageNum(PageNum that) {
		this.pageNum = that.pageNum;
	}
	
	public PageNum(int pageNum) {
		this.pageNum= pageNum;
	}
	
	public int getPageNum() {
		return pageNum;
	}
	
	public void setPageNum(int value) {
		this.pageNum = value;
	}
	
	public void setPageNum(PageNum pageNum) {
		this.pageNum = pageNum.pageNum;
	}
	
	public void addOne() {
		this.pageNum++;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + pageNum;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		PageNum other = (PageNum) obj;
		if (pageNum != other.pageNum)
			return false;
		return true;
	}
	
}
